package com.turing.data.engine;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.TreeSet;
import java.util.stream.Collectors;

import com.turing.data.vo.out.review.TaskElementVO;

public class Group {

    public static Map<Integer, List<Page>> merge(List<Page> pages) {
        return pages.stream().collect(Collectors.groupingBy(Page::getPageNo));
    }

    public static List<TaskElementVO.DrawResultVO> removeDuplicated(List<TaskElementVO.DrawResultVO> source) {
        return source.stream().collect(
                Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(TaskElementVO.DrawResultVO::getText))),
                        ArrayList::new));
    }

    public static List<TaskElementVO.DrawResultVO> sortByPosition(List<TaskElementVO.DrawResultVO> source) {

        return source.stream().sorted(Comparator.comparing(TaskElementVO.DrawResultVO::getStart)).collect(Collectors.toList());

    }


}
